package com.egao.common.core.utils;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Damon
 * @create 2021-02-24 14:56
 */
public class qxx {


    public static void main(String[] args) {
        ExcelReader reader = ExcelUtil.getReader("d:/a.xlsx");
        List<List<Object>> readAll = reader.read();
        reader = ExcelUtil.getReader("d:/b.xlsx");
        List<List<Object>> readAll2 = reader.read();
        readAll.addAll(readAll2);
        List<QxxEntity> qxxList = new ArrayList<>();
        for(int i =0; i < readAll.size(); i ++) {
            List<Object> a = readAll.get(i);
            QxxEntity c = new QxxEntity();
            c.setName(a.get(0).toString());
            c.setPerson(a.get(1).toString());
            c.setCity(a.get(2).toString());
            c.setDistrict(a.get(3).toString());
            c.setPhone(a.get(4).toString());
            c.setAddress(a.get(5).toString());
            try {
                c.setAddress2(a.get(6).toString());
            } catch (Exception e) {

            }
            qxxList.add(c);
        }

        List<QxxEntity> result = new ArrayList<>();
        for (QxxEntity user : qxxList) {
            if (user.getName().equals("aa")) {
                System.out.println(1);
            }
            boolean b = true;
            for (QxxEntity user2 : result) {
                if (user2.getName().equals(user.getName())) {
                    b = false;
                    break;
                }
            }
            if (b) {
                result.add(user);
            }
        }

        //通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("d:/c.xlsx");
        //通过构造方法创建writer
        //ExcelWriter writer = new ExcelWriter("d:/writeTest.xls");

        //一次性写出内容，强制输出标题
        writer.write(result, true);
        //关闭writer，释放内存
        writer.close();
    }

}